//
//  MainViewController.m
//  RoadVehicles
//
//  Created by appleLJ on 2018/2/26.
//  Copyright © 2018年 appleLJ. All rights reserved.
//

#import "MainViewController.h"
#import "MallViewController.h"
#import "CartViewController.h"
#import "OrderListViewController.h"
#import "MineViewController.h"
#import "IWTabBar.h"
#import "WeChatLoginViewController.h"
#import "FromMineLoginViewController.h"

@interface MainViewController ()<IWTabBarDelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化一个自定义的tabbar
    IWTabBar *tabbar = [[IWTabBar alloc] init];
    tabbar.delegate = self;
    //因为是只读属性,所以通过kvc的方式去赋值
    [self setValue:tabbar forKeyPath:@"tabBar"];
    
    MallViewController *mallVc = [[MallViewController alloc] init];
    CartViewController *cartVc = [[CartViewController alloc] init];
    OrderListViewController *orderListVc = [[OrderListViewController alloc] init];
    MineViewController *mineVc = [[MineViewController alloc] init];
    FromMineLoginViewController *weChatVc = [[FromMineLoginViewController alloc] init];

    [self addchildViewVc:mallVc withImagName:@"homeUnselect" withSelectedImageName:@"homeSelect" andTitle:@"商城"];
    [self addchildViewVc:cartVc withImagName:@"cartUnselect" withSelectedImageName:@"cartSelect"  andTitle:@"购物车"];
    [self addchildViewVc:orderListVc withImagName:@"orderListUnselect" withSelectedImageName:@"orderListSelect"  andTitle:@"订单"];
//    if ([[UserModel sharedInstanced].token isEqualToString:@""] || [UserModel sharedInstanced].token == nil || [[UserModel sharedInstanced].token length] == 0 || [[UserModel sharedInstanced].mobile isEqualToString:@""] || [UserModel sharedInstanced].mobile == nil || [[UserModel sharedInstanced].mobile length] == 0){
//        [UserModel sharedInstanced].token = @"";
//        [UserModel sharedInstanced].mobile = @"";
//        [self addchildViewVc:weChatVc withImagName:@"myUnselect" withSelectedImageName:@"mySelect"  andTitle:@"我的"];
//    }else{
        [self addchildViewVc:mineVc withImagName:@"myUnselect" withSelectedImageName:@"mySelect"  andTitle:@"我的"];
//    }
    
}
//添加子控制器方法
- (void)addchildViewVc:(UIViewController *)vc withImagName:(NSString *)imgName withSelectedImageName:(NSString *)selectedImgName andTitle:(NSString *)titile{
    //设置标题
    vc.title = titile;
    //vc.navigationController.title = titile;
    //设置选中状态item背景颜色
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:DEF_FontSize_14} forState:UIControlStateSelected];
    
    UIImage * unSelectImg = [UIImage imageNamed:imgName];
    unSelectImg = [unSelectImg  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * selectImge = [UIImage imageNamed:selectedImgName];
    selectImge = [selectImge imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置图片
    vc.tabBarItem.image = unSelectImg;
    //设置选中图片
    vc.tabBarItem.selectedImage = selectImge;
    
    //添加子控制器
    UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:vc];
    [[UINavigationBar appearance] setTranslucent:NO];
    [self addChildViewController:navVc];
}

#pragma mark -- IWTabBarDelegate
- (void)tabBar:(IWTabBar *)tabBar didSelectPlusButton:(UIButton *)button{
    NSLog(@"aaaa");
}
//
////三个全屏方法
//- (BOOL)shouldAutorotate {
//    return [self.selectedViewController shouldAutorotate];
//}
//- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
//    return [self.selectedViewController supportedInterfaceOrientations];
//}
//- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
//    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
//}


@end
